﻿/*

  The contents of this file are subject to the Mozilla Public License Version
  1.1 (the "License"); you may not use this file except in compliance with
  the License. You may obtain a copy of the License at 
  
           http://www.mozilla.org/MPL/ 
  
  Software distributed under the License is distributed on an "AS IS" basis,
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  for the specific language governing rights and limitations under the License. 
  
  The Original Code is AST'r Framework.
  
  The Initial Developer of the Original Code is
  ALCARAZ Marc (aka eKameleon) <ekameleon@gmail.com>.
  Portions created by the Initial Developer are Copyright (C) 2004-2011
  the Initial Developer. All Rights Reserved.
  
  Contributor(s) :
  
*/
package astro 
{
    import astro.display.MyDisplay;

    import core.reflect.getClassPackage;

    import graphics.FillStyle;

    import lunas.components.buttons.FrameLabelButton;

    import system.logging.LoggerLevel;
    import system.logging.targets.SOSTarget;
    import system.logging.targets.TraceTarget;
    import system.process.Action;

    import vegas.display.Root;
    import vegas.ioc.io.ObjectResourceInfo;
    import vegas.net.ApplicationLoader;

    import flash.events.Event;
    import flash.events.ProgressEvent;
    
    [SWF(width="740", height="460", frameRate="24", backgroundColor="#666666")]
        /**
     * The main Application class of the application.
     */
    public class Application extends Root
    {
        /**
         * Creates a new Application instance.
         */
        public function Application()
        {
            // logging
            
            var traceTarget:TraceTarget = new TraceTarget() ;
            traceTarget.filters         = ["*"] ;
            traceTarget.level           = LoggerLevel.ALL ;
            traceTarget.includeLines    = true  ;
            traceTarget.includeTime     = true  ;
            
            var sosTarget:SOSTarget = new SOSTarget( getClassPackage(this) , 0xFFD9A2 ) ;
            sosTarget.filters       = ["*"] ;
            sosTarget.level         = LoggerLevel.ALL ;
            sosTarget.includeLines  = true  ;
            sosTarget.includeTime   = true  ;
            
            // IoC
            
            var loader:ApplicationLoader = new ApplicationLoader( "application.eden" , "context/" ) ;
            
            loader.finishIt.connect( finish ) ; 
            loader.startIt.connect( start ) ;
            
            loader.resourceInfo.addEventListener( Event.OPEN             , debug ) ;
            loader.resourceInfo.addEventListener( ProgressEvent.PROGRESS , debug ) ;
            loader.resourceInfo.addEventListener( Event.COMPLETE         , debug ) ;
            
            loader.root  = this ;
            loader.stage = stage ;
            
            loader.run() ;
        }
        
        public function debug( e:Event ):void
        {
            var info:ObjectResourceInfo = e.target as ObjectResourceInfo ;
            if ( info != null )
            {
                logger.debug( e.type + " : " + info.resource + " :: " + info.bytesLoaded + " / " + info.bytesTotal ) ;
            }
        }
        
        /**
         * Invoked when the IoC factory is initialized.
         */
        public function finish( action:Action ):void
        {
            logger.info( this + " finish" ) ;
        }
        
        /**
         * Invoked when the IoC factory start the initialization.
         */
        public function start( action:Action ):void
        {
            logger.info( this + " start" ) ;
        }
        
        ////// LINKAGE ENFORCER
        
        // astro.display
        
        MyDisplay ;  
        
        // graphics
        
        FillStyle ;
        
        // lunas
        
        FrameLabelButton ; 
    }
}
